Home:ALL Converter>Mongo DB query - Transform unix date from document in Date Object to compare

Mongo DB query - Transform unix date from document in Date Object to compare

Ask Time:2022-05-25T18:26:07         Author:Paulo Barbosa

Json Formatter

I want make a query to return all documents from a collection created in that day. This is what i done so far:

db.entities.find({"creDate":{"$gte": new Date(Date.now() - (1000 * 60 * 60 * 24))}});

The problem is that the atributte "creDate" format is unix. Example: 1653408094.1847994

So, in the above query i need to convert "creDate" to Date Object. Thanks!

Author:Paulo Barbosa,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/72375910/mongo-db-query-transform-unix-date-from-document-in-date-object-to-compare
yy